﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace AcctrueWMS.Foundation.Data
{
    public class PrimaryKeyConBuilder
    {
        /// <summary>
        /// 将主键串合成为查询条件
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string BuildPrimaryKeyCon(string ID, DataModel model)
        {
            string queryStr = "1=1 ";
            //[key1=1,key2=2]
            ID = HttpUtility.UrlDecode(ID);
            ID = ID.Replace("[", "").Replace("]", "");
            string[] kevs = ID.Split(',');
            for (int i = 0; i < kevs.Length; i++)
            {
                string key = kevs[i].Split('=')[0];
                string value = kevs[i].Split('=')[1];
                queryStr += " and " + model.Name + "." + key + "='" + value + "'";
            }
            return queryStr;
        }
    }
}
